<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: xajax.misc.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$xajax->registerFunction('emptyDiv');
$xajax->registerFunction('message');
$xajax->registerFunction('dialog');

function emptyDiv($div_array, $hide_layer = false) {
	$ajax = new xajaxResponse();

	if(is_array($div_array)) {
		foreach($div_array AS $div) {
			$ajax->assign($div, 'innerHTML', '');
			$ajax->assign($div, 'style.display', 'none');
		}
	} elseif (!empty($div_array)) { // einfacher String
		$ajax->assign($div_array, 'innerHTML', '');
		$ajax->assign($div_array, 'style.display', 'none');
	}
	if($hide_layer)
		$ajax->assign('show_overlay', 'style.display', 'none');

	return $ajax;
}

function message($msg, $type) {
	$ajax = new xajaxResponse();
	
	if($type == 'error')
		$title = 'Fehler';
	elseif($type == 'success')
		$title = 'Erfolg';
	elseif($type == 'warning')
		$title = 'Hinweis';
	
	$j .= '$.gritter.add({'."\n";
	$j .= '		title: \''.$title.'\','."\n";
	$j .= '		text: \''.$msg.'\','."\n";
	$j .= '		image: \''.DIR_WS_ICONS.'dialog-'.$type.'.png\','."\n";
	$j .= '		sticky: false,'."\n";
	$j .= '		time: 3500'."\n";
	$j .= '});';

	return $ajax->script($j);
}

function dialog($msg, $title, $w, $h) {
	$ajax = new xajaxResponse();
	
	#$ajax->script('$(\'.ui-dialog-content\').dialog(\'close\');');
	
	$ajax->script('	var dialog = $(\'<div style="display:none"></div>\').appendTo(\'body\');
					dialog.dialog({
						close: function(event, ui) {dialog.remove();},
						modal: true,
						title: \''.$title.'\',
						width: '.$w.',
						height: '.$h.'
					});
					dialog.html(\''.$msg.'\');
					$(\'.ui-dialog\').css({position:\'fixed\'});
					$(\'.ui-dialog-content\').css({backgroundImage:\'none\'});');
	return $ajax;
}